<template>
  <div class="wfull">
    <a-empty v-if="obj===null"></a-empty>
    <a-form v-else :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
      <a-form-item label="图标">
        <ZgInput :width="200" v-model="obj.icon"></ZgInput><a-icon :type="obj.icon"/>
      </a-form-item>
      <a-form-item label="名称" required>
        <ZgInput v-model="obj.name"></ZgInput>
      </a-form-item>
      <a-form-item label="编码" required>
        <ZgInput v-model="obj.code"></ZgInput>
      </a-form-item>
      <a-form-item label="状态" required>
        <ZgSwitch v-model="obj.isUse"></ZgSwitch>
      </a-form-item>
    </a-form>
  </div>
</template>
<script>
export default {
  props: {
    jsonStr: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      obj: null
    }
  },
  watch: {
    jsonStr () {
      this.init()
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      if (this.jsonStr && this.jsonStr.length > 0) {
        this.obj = JSON.parse(this.jsonStr)
      }
    },
    save () {
      if (this.obj.name.length === 0) {
        return this.$result.error('请输入名称')
      }
      if (this.obj.code.length === 0) {
        return this.$result.error('请输入编码')
      }
      return this.$result.ok(Object.assign({}, this.obj))
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
